#include "progressbardelegate.h"

ProgressBarDelegate::ProgressBarDelegate(const DownloaderWindow* const window, QObject *parent) :
    QItemDelegate(parent), window(window)
{
}


void ProgressBarDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const{
    QStyleOptionProgressBar progressBarOption;
    progressBarOption.state = QStyle::State_Enabled;
    progressBarOption.direction = QApplication::layoutDirection();
    progressBarOption.rect = option.rect;
    progressBarOption.fontMetrics = QApplication::fontMetrics();
    progressBarOption.minimum = 0;
    progressBarOption.maximum = 100;
    progressBarOption.textAlignment = Qt::AlignCenter;
    progressBarOption.textVisible = true;

    double progress = window->getByRow(index.row())->getProgress();

    //int progress = 50;
    progressBarOption.progress = progress * 100;
    progressBarOption.text = QString().sprintf("%d%%", progressBarOption.progress);

    QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter);
}
